﻿using System;
using System.Windows.Forms;
using System.Xml;
using System.Collections.Generic;

namespace CSharp
{
    //[STAThread]
    class Graph
    {
        List<int> nd_Id;
        WayInfo way; // obj from wayinfo class.
        bool way_check = true;   // to check if the last read is way or not. to tell me if make new list to insert node of this way.
        int way_Id;
        List<WayInfo> graph = new List<WayInfo>();  // our graph.
        int i = 0; // 
        // read the xml file
        public string Read()
        {
             OpenFileDialog dlg = new OpenFileDialog();
            if (dlg.ShowDialog() == DialogResult.OK)
                Console.WriteLine(dlg.FileName);
            return dlg.FileName;
        }
        
        public void Read_Way()  //reads ways from xml file
        {
            string fname = Read();
               
            XmlTextReader reader = new XmlTextReader(fname);
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "way")
                    {
                        if (i > 0)
                        {
                            way = new WayInfo(way_Id, nd_Id);
                            graph.Add(way);
                        }
                        Console.WriteLine("Way: " + reader.GetAttribute(0));
                        way_Id = Int32.Parse(reader.GetAttribute(0));
                        nd_Id = new List<int>();
                        i++;
                    }

                    if (reader.Name == "nd")
                    {
                        Console.WriteLine(reader.GetAttribute(0));
                        nd_Id.Add(Int32.Parse(reader.GetAttribute(0)));
                    }
                }
            }
        }
    }
}
